Okay... so there's a funny story...
As I registered in this ML Study Jam, they gave me "credits" to access each lesson in Machine Learning APIs course. To complete the course, I need to answer all the quizes in each lesson with the access granted. Even funnier is these "credits" only valid in THIS ONE MONTH.
To make the story short, we need to skip the 2 hands-on labs as mentioned in the first article and jump right into the first lesson of Machine Learning APIs - Introduction to APIs in Google
Life is full of surprises right?!
No more wasting time~ Let's start!
In this lesson, you will learn:
Google APIs
An API (Application Programming Interface) is a software program that gives developers access to computing resources and data.
Google offers APIs that can be applied to many different fields and sectors. APIs are often used in web development, machine learning, data science, and system administration workflows.
API architecture: Client-server model
The internet is the standard communication channel that APIs use to transmit requests and responses between programs. The client-server model is the underlying architecture that web-based APIs use for exchanging information.
This is a visual representation of the client-server model:
The client is a computing device (e.g. a smartphone, laptop, etc.) that makes a request for some computing resource or data. The client's request needs to be formatted in the agreed upon protocol.
The server has data and/or computing resources stored on it. Its job is to interpret and fulfill a client's request.
HTTP protocol and request methods
Since APIs use the web as a communication channel, many of them adhere to the HTTP protocol, which specifies rules and methods for data exchange between clients and servers over the internet.
APIs that utilize the HTTP protocol use HTTP request methods for transmitting client requests to servers. The most commonly used HTTP request methods are GET, POST, PUT, and DELETE.
GET -> is used by a client to fetch data from a server. If the requested resource is found on the server, it will then be sent back to the client.
PUT -> replaces existing data or creates data if it does not exist. If you use PUT many times, it will have no effect — there will only be one copy of the dataset on the server.
POST -> is used primarily to create new resources. Using POST many times will add data in multiple places on the server. It is recommended to use PUT to update resources and POST to create new resources.
DELETE -> removes data or resources specified by the client on a server.
Endpoints
Endpoints are access points to data or computing resources hosted on a server and they take the form of an HTTP URI. Endpoints are added to an API's base URL (e.g. http://example.com) to create a path to a specific resource or container of resources.
The following are some examples of endpoints:
You can add query strings to endpoints (e.g. http://example.com/students/?id=1) to pass in variables that may be needed to complete an API's request.
RESTful APIs
APIs that utilize the HTTP protocol, request methods, and endpoints are referred to as RESTful APIs. REST (Representational State Transfer) is an architectural style that prescribes standards for web-based communication.
REST is the most widely used framework for APIs. In 2010, about 74% of public network APIs were HTTP REST APIs.
Besides query strings, RESTful APIs can also use the following fields in their requests:
The body is written in the JSON or XML data formatting language.
API Data Formats (JSON)
JSON(JavaScript Object Notation) has surpassed XML in RESTful API use largely because JSON is lightweight, easier to read, and faster to parse.
JSON supports the following data types:
A JSON object uses curly braces { } to group data that's arranged in key-value pairs. Commas separate the key-value pairs stored in an object.
Ex:
{
"teacher": "Julie",
"students": ["Alice", "John", "Tom", "Kent"],
"class": "3-A",
"number-of-students-sick": 10,
"is-ready-to-start-lesson": false
}
Authentication and Authorization
In a simple way of saying, authentication identifies who you are, and authorization determines what you can do.
Google APIs use these 3 types of authentication/authorization services:
Wow! Didn't expect we have so many things to introduce today.
Really appreciate you finish reading this long article and hope you get more familiar with APIs. (Or probably it's too easy for you if you are already very proficient at it XD